define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'card/storecancel/index',
                    add_url: 'card/storecancel/add',
                    edit_url: 'card/storecancel/edit',
                    del_url: 'card/storecancel/del',
                    multi_url: 'card/storecancel/multi',
                    table: 'store_cancel',
                }
            });

            //字段名
            var button_arr = [];
            if(use_type == 0){//超级管理员
                button_arr = [
                    {
                        name: 'read',
                        text: __('编辑'),
                        title: __('编辑'),
                        icon: 'fa fa-edit',
                        classname: 'btn btn-xs btn-success btn-dialog', url: 'card/storecancel/edit'},
                    {
                        name: 'del',
                        text: __('Del'),
                        title: __('Del'),
                        icon: 'fa fa-trash',
                        classname: 'btn btn-xs btn-ajax btn-danger btn-delone',
                        url: 'card/storecancel/del',
                        confirm: '确定要执行该操作吗?'},
                ];
            }else{//商家
                button_arr = [
                    {
                        name: 'read',
                        text: __('编辑'),
                        title: __('编辑'),
                        icon: 'fa fa-edit',
                        classname: 'btn btn-xs btn-success btn-dialog',
                        url: 'card/storecancel/edit'
                    }
                ];
            }

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'store_id', title: __('Store_id')},
                        {field: 's_name', title: __('店铺名')},
                        // {field: 'openid', title: __('Openid')},
                        // {field: 'unionid', title: __('Unionid')},
                        // {field: 'mp_openid', title: __('Mp_openid')},
                        {field: 'wechat_num', title: __('Wechat_num')},
                        {field: 'phone', title: __('手机号')},
                        {field: 'province', title: __('Province')},
                        {field: 'city', title: __('City')},
                        // {field: 'pass_check',title:__('审核情况'),formatter:function(res){
                        //     // if(res == '0'){
                        //     //     return '待添加';
                        //     // }else if(res == '1'){
                        //     //     return '添加成功';
                        //     // }else{
                        //     //     return '添加失败';
                        //     // }
                        //     // return res;
                        // }},
                        {field: 'check_data_text', title: __('审核情况'), operate:false},
                        {field: 'avatar', title: __('Avatar'), formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'id', title: __('Operate'), table: table, buttons:button_arr, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,operate:false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            var btn = $('#form-submit');
            btn.click(function(){
                //定时跳转
                setTimeout(function(){
                    window.history.back(-1);
                },1000);
            });
        },
        edit: function () {
            Controller.api.bindevent();
            //在加载完成后
            $(function(){
                //被选中的值
                var check = $("input[name='row[check_pass]']:checked").val();
                var reason = $('#reason-box');
                if(check == 2){ //为不通过时,显示输入原因
                    reason.removeClass('hidden');
                }
                var check_pass = $("input[name='row[check_pass]']");
                check_pass.change(function(){
                    if($(this).val() == 2){
                        reason.removeClass('hidden');
                    }else{
                        reason.addClass('hidden');
                    }
                });
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});